package com.ww7h.ui.base.ui

import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.os.PersistableBundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.ww7h.ui.mvvm.v.ViewCommon

/**
 * ================================================
 * 描述：
 * 来源：     Android Studio.
 * 项目名：   BigObj
 * 包名：     com.ww7h.common
 * 创建时间：  2020/11/3 02:10
 * @author   ww
 * ================================================
 */
abstract class BaseActivity<VDB : ViewDataBinding> : AppCompatActivity() {

    protected open lateinit var defaultViewDataBinding: VDB
    protected val viewCommon: ViewCommon by lazy {
        ViewCommon()
    }

    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onCreate(savedInstanceState, persistentState)
        defaultViewDataBinding = DataBindingUtil.setContentView(this, getContentView())
    }

    abstract fun getContentView(): Int

    protected fun <VDB : ViewDataBinding> getViewDataBinding(
        inflater: LayoutInflater,
        viewGroup: ViewGroup,
        layoutId: Int
    ): VDB {
        return viewCommon.getViewDataBinding(inflater, viewGroup, layoutId)
    }

    protected open fun clearUseViewDataBindingArrayCache(layoutId: Int) {
        viewCommon.clearUseViewDataBindingArrayCache(layoutId)
    }

    protected open fun initFullScreen() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
            val decorView = window.decorView
            decorView.systemUiVisibility =
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
            window.statusBarColor = Color.TRANSPARENT
        }
    }

}